package persistency.controller;

import model.Business;
import model.Registration;
import persistency.ArgIO;

public class OfferedCourseRegistrationController extends BusinessController {
	private StringBuilder callableStatement;
	private static OfferedCourseRegistrationController instance = new OfferedCourseRegistrationController();

	private OfferedCourseRegistrationController() {
	}

	public static OfferedCourseRegistrationController instance() {
		return instance;
	}

	public boolean insertOfferedCourseRegistration(Registration registration) {
		callableStatement = new StringBuilder("{call sp_insertofferedcourseregistration(?,?,?)}");
		return insert(registration, callableStatement, 3);

	}

	@Override
	public void prepare(Business business, Object[] args, int[] argsType, ArgIO[] argsIO, int i) throws Exception {
		Registration registration = (Registration) business;
		switch (i) {
		case 0: {
			args[i] = registration.getOfferedCourse().getId();
			argsType[i] = java.sql.Types.INTEGER;
			argsIO[i] = ArgIO.IN;
			break;
		}
		case 1: {
			args[i] = registration.getId();
			argsType[i] = java.sql.Types.INTEGER;
			argsIO[i] = ArgIO.IN;
			break;
		}
		case 2: {
			args[i] = registration.isReceiveCourseEmail();
			argsType[i] = java.sql.Types.BOOLEAN;
			argsIO[i] = ArgIO.IN;
			break;
		}
		default:
			throw new Exception("Error while creating SP OfferedCourseRegistrationController");

		}
	}

}
